package com.example.jupiter

import android.media.Image
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Email
import androidx.compose.material.icons.rounded.Menu
import androidx.compose.material.icons.rounded.Phone
import androidx.compose.material.icons.rounded.Share
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.input.pointer.motionEventSpy
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.layout.VerticalAlignmentLine
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.LineHeightStyle
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.jupiter.ui.theme.JupiterTheme


class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
            Surface(
                modifier = Modifier.fillMaxSize(),
                color = MaterialTheme.colorScheme.background
            ) {
//                ShowArticle()
            }
        }
    }


    @Preview(showBackground = true)
    @Composable
    fun JupiterPreview() {
        JupiterTheme {
//        ShowArticle()
//        ComposeQuadrantApp()
            NameCard()
        }
    }

    @Composable
    fun DoGreetingText() {
        GreetingText(
            message = stringResource(R.string.happy_birthday_text), from = stringResource(
                R.string.signature_text
            )
        )
    }

    @Composable
    fun GreetingText(message: String, from: String, modifier: Modifier = Modifier) {
        Column(
            verticalArrangement = Arrangement.Center,
            modifier = modifier.padding(8.dp)
        ) {
            Text(
                text = message,
                fontSize = 90.sp,
                lineHeight = 116.sp,
                textAlign = TextAlign.Center
            )
            Text(
                text = from,
                fontSize = 36.sp,
                modifier = Modifier
                    .padding(16.dp)
                    .align(alignment = Alignment.CenterHorizontally)
            )
        }
    }

    @Composable
    fun GreetingImage(message: String, from: String, modifier: Modifier = Modifier) {
        val image = painterResource(R.drawable.androidparty)
        Box(modifier) {
            Image(
                painter = image,
                contentDescription = null,
                contentScale = ContentScale.Crop,
                alpha = 0.5F
            )
            GreetingText(
                message = message,
                from = from,
                modifier = Modifier
                    .fillMaxSize()
                    .padding(8.dp)
            )
        }
    }


    @Composable
    fun ShowArticle() {
        ArticleCard(
            image = painterResource(R.drawable.bg_compose_background),
            title = stringResource(R.string.title),
            content1 = stringResource(R.string.content1),
            content2 = stringResource(R.string.content2)
        )
    }

    @Composable
    fun ArticleCard(
        image: Painter,
        title: String,
        content1: String,
        content2: String
    ) {
        Column {
            Image(painter = image, contentDescription = "article")
            Text(
                text = title,
                fontSize = 24.sp,
                modifier = Modifier.padding(16.dp),
            )
            Text(
                text = content1,
                textAlign = TextAlign.Justify,
                modifier = Modifier.padding(start = 16.dp, end = 16.dp),
            )
            Text(
                text = content2,
                textAlign = TextAlign.Justify,
                modifier = Modifier.padding(16.dp)
            )
        }
    }

    @Composable
    fun ComposeQuadrantApp() {
        Column(Modifier.fillMaxWidth()) {
            Row(Modifier.weight(1f)) {
                ComposableInfoCard(
                    title = stringResource(R.string.first_title),
                    description = stringResource(R.string.first_description),
                    backgroundColor = Color(0xFFEADDFF),
                    modifier = Modifier.weight(1f)
                )
                ComposableInfoCard(
                    title = stringResource(R.string.second_title),
                    description = stringResource(R.string.second_description),
                    backgroundColor = Color(0xFFD0BCFF),
                    modifier = Modifier.weight(1f)
                )
            }
            Row(Modifier.weight(1f)) {
                ComposableInfoCard(
                    title = stringResource(R.string.third_title),
                    description = stringResource(R.string.third_description),
                    backgroundColor = Color(0xFFB69DF8),
                    modifier = Modifier.weight(1f)
                )
                ComposableInfoCard(
                    title = stringResource(R.string.fourth_title),
                    description = stringResource(R.string.fourth_description),
                    backgroundColor = Color(0xFFF6EDFF),
                    modifier = Modifier.weight(1f)
                )
            }
        }
    }

    @Composable
    private fun ComposableInfoCard(
        title: String,
        description: String,
        backgroundColor: Color,
        modifier: Modifier = Modifier
    ) {
        Column(
            modifier = modifier
                .fillMaxSize()
                .background(backgroundColor)
                .padding(16.dp),
            verticalArrangement = Arrangement.Center,
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
            Text(
                text = title,
                modifier = Modifier.padding(bottom = 16.dp),
                fontWeight = FontWeight.Bold
            )
            Text(
                text = description,
                textAlign = TextAlign.Justify
            )
        }
    }

    @Composable
    fun NameCard() {
//        modifier = Modifier.padding(50.dp)
//            .fillMaxSize()
//            .background(Color.Gray)
//            .padding(16.dp)
        val logo = painterResource(R.drawable.android_logo)
        Column (
            verticalArrangement = Arrangement.Center,
            horizontalAlignment = Alignment.CenterHorizontally,
            modifier = Modifier
                .padding(top = 0.dp)
                .fillMaxSize()
                .background(Color(0xFF8BB799))){

            Column(
                verticalArrangement = Arrangement.Center,
                horizontalAlignment = Alignment.CenterHorizontally,
                modifier = Modifier.weight(1f)
            ) {
                Image(
                    painter = logo,
                    contentDescription = "hello",
                    modifier = Modifier
                        .padding(16.dp)
                        .background(Color(0XFF073042))
                        .height(100.dp)
                )
                Text(
                    text = "Jennifer Doe",
                    textAlign = TextAlign.Center,
                    fontSize = 50.sp,
                    modifier = Modifier.padding(8.dp)

                )
                Text(
                    text = "Android Developer Extraordinaire",
                    textAlign = TextAlign.Center,
                    color = Color(0xFF0E7543),
                    fontSize = 20.sp,
                    modifier = Modifier.padding(bottom = 120.dp)
                )
            }
            Column(
                verticalArrangement = Arrangement.Bottom,
                horizontalAlignment = Alignment.Start,
                modifier = Modifier.padding(bottom = 100.dp)
            ) {
                InfoCard(Icons.Rounded.Phone, "+11 (123) 444 555 666")
                InfoCard(Icons.Rounded.Share, "@AndroidDev")
                InfoCard(Icons.Rounded.Email, "jen.doe@android.com")
            }
        }
    }

    @Composable
    fun InfoCard(icon: ImageVector, content: String) {
        Row {
            Icon(icon, contentDescription = "Localized description",
                tint = Color(0XFF006C3A),modifier = Modifier.padding(end = 16.dp))
            Text(text = content)
        }
    }
}